﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CH.TestData.Common;
namespace CH.TestData.Provider
{

    [DataTypeName("日期")]
    public class DateProvider : IDataProvider
    {

        private DateTime from;
        private DateTime to;
        private string columnName;
        public void SetDataSource(FlowLayoutPanel flp)
        {
            TextBox txtColumnName = flp.Controls.Find("txtColumnName", false).First() as TextBox;
            this.columnName = txtColumnName.Text;




            DateTimePicker dtpFrom = flp.Controls.Find("dtpFrom", true).First() as DateTimePicker;
            from = dtpFrom.Value;

            DateTimePicker dtpTo = flp.Controls.Find("dtpTo", true).First() as DateTimePicker;
            to = dtpTo.Value;

        }
        public void CreateOption(FlowLayoutPanel flp)
        {
            Label lblc = new Label();
            lblc.Text = "从";
            lblc.Width = 30;
            lblc.Margin = new Padding(0, 7, 0, 0);
            flp.Controls.Add(lblc);

            DateTimePicker dtpFrom = new DateTimePicker();
            dtpFrom.Name = "dtpFrom";
            dtpFrom.Text = DateTime.Now.AddYears(-1).ToString();
            dtpFrom.Margin = new Padding(0, 3, 0, 0);
            flp.Controls.Add(dtpFrom);

            Label lbld = new Label();
            lbld.Text = "开始,到";
            lbld.Width = 60;
            lbld.Margin = new Padding(0, 7, 0, 0);
            flp.Controls.Add(lbld);

            DateTimePicker dtpTo = new DateTimePicker();
            dtpTo.Name = "dtpTo";
            dtpTo.Text = DateTime.Now.ToString();
            dtpTo.Margin = new Padding(0, 3, 0, 0);
            flp.Controls.Add(dtpTo);

            Label lblzf = new Label();
            lblzf.Text = "结束";
            lblzf.Width = 50;
            lblzf.Margin = new Padding(0, 7, 0, 0);
            flp.Controls.Add(lblzf);
        }

        public string GetNextValue()
        {
            TimeSpan ts = to - from;
            int minute = new Random(Guid.NewGuid().GetHashCode()).Next(1, (int)ts.TotalMinutes);
            return "N'" + from.AddMinutes(minute).ToString() + "'";
        }

       
    }
}
